<?php /* Smarty version 2.6.20, created on 2012-04-10 19:37:05
         compiled from _core/pagecommon/_mvc/_control/handlepagesumexpensedetail.tpl */ ?>
function HandlePageSumExpenseDetail(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options

  this._createElements();
};

HandlePageSumExpenseDetail.prototype._createElements = function() {
  var _self = this;
  
  tr = this._gui.topTable.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 4;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageSumExpenseDetail.prototype._loadData = function() {
  this._results = null;
  this._parameters = null;
  this._expenses = null;
  this._retrieveResults(1);
  this._retrieveExpenses(1);
};

HandlePageSumExpenseDetail.prototype._verifyData = function() {
  if (this._results && this._expenses) {
    this._updateElements();
  }
};

HandlePageSumExpenseDetail.prototype._retrieveResults = function(page) {
  var _self = this;
  var args = '&c=' + 'd.particular=\'' + encodeURIComponent(this._options.name) + '\'' + '&p=' + page + '&from=' + JSON.stringify(this._options.from) + '&to=' + JSON.stringify(this._options.to);
  /*new RequestUtils()._custom('iesumexpensedetail', args, function(result, params) { _self._results = result;
                                                                                    _self._verifyData.call(_self);
                                                                                  }, null);
*/
  new RequestUtils()._mysql('iesumexpensedetail', args, function(result, params) { _self._results = result;
                                                                             _self._verifyData.call(_self);
                                                                           }, null);  
};

HandlePageSumExpenseDetail.prototype._retrieveExpenses = function(page) {
  var _self = this;
  var args = '&c=' + 'd.particular=\'' + encodeURIComponent(this._options.name) + '\'' + '&p=' + page + '&from=' + JSON.stringify(this._options.from) + '&to=' + JSON.stringify(this._options.to) + '&s=' + DlmanageUtils.number + '&ss=' + 1;
  /*new RequestUtils()._custom('expenses', args, function(result, params) { _self._expenses = result.data;
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, null);
*/
  new RequestUtils()._mysql('expenses', args, function(result, params) { _self._expenses = result.data;
                                                                         _self._parameters = result;
                                                                         _self._verifyData.call(_self);
                                                                           }, null);  
};

HandlePageSumExpenseDetail.prototype._updateElements = function() {
  var _self = this;
  DOMUtils.removeChildElements(this._gui.title);
  DOMUtils.removeChildElements(this._gui.pagination);
  DOMUtils.removeTableRows(this._gui.topTable, 1);
  DOMUtils.removeTableRows(this._gui.mains, 1);
  
  this._gui.title.appendChild(document.createTextNode((this._options.name).toUpperCase()));
  
  for (var i = 0, il = this._results.top.length; i < il; i++) {
    var result = this._results.top[i];
    
    tr = this._gui.topTable.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(result.payee));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('$' + parseFloat(result.total).toFixed(2)));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('$' + parseFloat(result.cash).toFixed(2)));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('$' + parseFloat(result.noncash).toFixed(2)));
  }

  for (var i = 0, il = this._expenses.length; i < il; i++) {
    var result = this._expenses[i];
    
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(SimpleDate.format(result.createdDate)));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(SimpleDate.format(result.payDate)));
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    td.appendChild(document.createTextNode(result.payee));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('$' + parseFloat(result.amount).toFixed(2)));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(result.method));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(result.chequeNumber));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode((result.ng == 1) ? 'Y' : 'N'));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode((result.ne == 1) ? 'Y' : 'N'));
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    td.appendChild(document.createTextNode(result.note));
  }
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveExpenses.call(_self, page, _self._parameters.condition); }, this, document);
};